<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('竞价信息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">


            <!--<div class="btn-group-sm" id="toolbar" role="group">-->
                <!--<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:bidinfo:add">-->
                    <!--<i class="fa fa-plus"></i> 添加-->
                <!--</a>-->
                <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:bidinfo:edit">-->
                    <!--<i class="fa fa-edit"></i> 修改-->
                <!--</a>-->
                <!--<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:bidinfo:remove">-->
                    <!--<i class="fa fa-remove"></i> 删除-->
                <!--</a>-->
                <!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:bidinfo:export">-->
                    <!--<i class="fa fa-download"></i> 导出-->
                <!--</a>-->
            <!--</div>-->
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">

        var data = [[${user}]];
        //此处的权限应为system:offerinfo:add
        var addFlag = [[${@permission.hasPermi('system:bidinfo:add')}]];
        var editFlag = [[${@permission.hasPermi('system:bidinfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:bidinfo:remove')}]];
        var prefix = ctx + "system/bidinfo";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "竞价信息",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'bidInfoId',
                    title: '竞价信息表ID',
                    visible: false
                },
//
                {
                    field: 'goodsName',
                    title: '采购商品'
                },
//                {
//                    field: 'purchasingUnitId',
//                    title: '采购单位ID'
//                },
//                {
//                    field: 'supplierId',
//                    title: '供应商ID'
//                },
                {
                    field: 'beginTime',
                    title: '开始时间'
                },
                {
                    field: 'endTime',
                    title: '结束时间'
                },
//                {
//                    field: 'successfulAmount',
//                    title: '中标金额'
//                },
//                {
//                    field: 'bidStatus',
//                    title: '竞价状态'
//                },
//                {
//                    field: 'isLowerest',
//                    title: '是否最低价'
//                },
                {
                    field: 'demand',
                    title: '商品要求'
                },
//                {
//                    field: 'lowerestNumber',
//                    title: '最低报价供应商个数'
//                },
                {
                    field: 'count',
                    title: '数量'
                },
                    {
                        field: 'createTime',
                        title: '创建时间'
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.offerAmount == null){
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="grant(\'' + row.bidInfoId + '\',\'' + row.count + '\',\'' + row.demand + '\',\'' + row.purchaseItemId + '\',\'' + row.offerAmount + '\',\'' + row.endTime + '\')"><i class="fa fa-edit"></i>报价</a> ');
                        }

                        return actions.join('');
                    }
                }]
            };
            if(data.userType=="11"){
                options.columns.splice(options.columns.length-2, 0, {
                    field: 'offerAmount',
                    title: '报价金额'
                });
            }
            $.table.init(options);
        });
        function grant(id,count,demand,purchaseItemId,money,endTime) {
            console.log(id)
            var dB = new Date(endTime.replace(/-/g, "/"));
            if (new Date() > Date.parse(dB)) {
                $.modal.alertError("截止时间已过，无法报价！");
            }else{
                if(money==null||money==""||money==undefined||money=="null"){
                    var url = '/system/offerinfo/addModel?bidInfoId='+id+'&purchaseItemId='+purchaseItemId +'&count='+count+'&demand='+demand;
                    $.modal.open("报价", url);
                }else{
                    $.modal.alertWarning("您已经参与了报价！");
                }
            }

        }
    </script>
</body>
</html>